import { noSystemReferences } from '@app-cad-env/product/utils';
import {
  PickInputRJSFFormat,
  NumberInputFormat,
} from '@app-cad/common/components/command-form/constants';
import { RJSFSchema } from '@rjsf/utils';
import { FormData } from './types';

export const schema: RJSFSchema = {
  properties: {
    select: {
      type: 'number',
      format: PickInputRJSFFormat.PickProduct,
    },
    distance: {
      title: '平移距离',
      type: 'array',
      items: [
        {
          title: 'X距离',
          type: 'number',
          format: NumberInputFormat.Length,
        },
        {
          title: 'Y距离',
          type: 'number',
          format: NumberInputFormat.Length,
        },
        {
          title: 'Z距离',
          type: 'number',
          format: NumberInputFormat.Length,
        },
      ],
    },
    angle: {
      title: '旋转角度',
      type: 'array',
      items: [
        {
          title: 'X角度',
          type: 'number',
          format: NumberInputFormat.Angle,
        },
        {
          title: 'Y角度',
          type: 'number',
          format: NumberInputFormat.Angle,
        },
        {
          title: 'Z角度',
          type: 'number',
          format: NumberInputFormat.Angle,
        },
      ],
    },
  },
};

export const defaultTransformation: Omit<FormData, 'select'> = {
  distance: [0, 0, 0],
  angle: [0, 0, 0],
};

export function getExtraUiSchema(formData: FormData) {
  return {
    select: {
      'ui:placeholder': '请输入零件',
      'ui:autofocus': true,
      'ui:options': {
        pickFilter: noSystemReferences,
        highlightSelection: false,
      },
      'ui:disabled': !!formData.select,
    },
    distance: {
      'ui:classNames': 'transform-distance',
      items: {
        'ui:options': {
          disableParameter: true,
        },
      },
    },
    angle: {
      'ui:classNames': 'transform-angle',
      items: {
        'ui:options': {
          disableParameter: true,
        },
      },
    },
  };
}
